﻿@model WaiGaoQiaoWeb.Models.BringVM
@{
    ViewBag.Title = "物品领用";
    Layout = "~/Views/Shared/_Layout.cshtml";
}
@section Head
{
    @Html.Css("EditForm", "RightSeparateModule", "dp")
    @Html.Js("datepicker")
    <script type="text/javascript">

        $(function () {

            var option = {
                height: 290,
                width: 800,
                url: '@Url.Action("GetUserBring")',
                colModel: [
                     { display: 'ID', name: 'ID', width: 60, sortable: false, align: 'left', hide: true, iskey: true },
                     { display: '物品名称', name: 'Article_ID', width: 120, sortable: false, hide: true, align: 'left' },
                     { display: '物品名称', name: 'Article_ID', width: 100, sortable: false, hide: false, align: 'left' },
                     { display: '物品规格', name: 'Article_Unit', width: 120, sortable: false, hide: true, align: 'left' },
                     { display: '物品规格', name: 'Article_Unit', width: 100, sortable: false, hide: false, align: 'left' },
                     { display: '领取数量', name: 'BringCount', width: 60, sortable: false, hide: false, align: 'left' },
                     { display: '工种(岗位)名称', name: 'postid', width: 120, sortable: false, hide: true, align: 'left' },
                     { display: '工种(岗位)名称', name: 'postid', width: 120, sortable: false, hide: false, align: 'left' },
                     { display: '间隔时间', name: 'clu', width: 100, sortable: false, hide: true, align: 'left' },
                     { display: '间隔月份', name: 'clu', width: 80, sortable: false, hide: false, align: 'left' },
                     { display: '工号', name: 'PersonNo', width: 60, sortable: false, hide: false, align: 'left' },
                     { display: '姓名', name: 'PersonName', width: 100, sortable: false, hide: false, align: 'left' },
                     { display: '上次领取日期', name: 'BringTime', width: 100, sortable: false, hide: false, align: 'left' }

               	],
                singleselected: true,
                sortname: "Sequence",
                sortorder: "asc",
                title: false,
                usepager: true,
                page: 1,
                rp: 20,
                rpoption: [10, 15, 20],
                showcheckbox: true,
                selectedonclick: true, //点击行是否选中
                rowbinddata: true
            };
            var instockgrid = $("#bringList").flexigrid(option);
            //保存
            $("#btnSave").click(function (event) {
                var items = $(instockgrid).getSelectedRows();
                if (items.length == 0) {
                    showLoadingMsg("请选择您要领用的物品!", { left: 400, top: 2 }, true, 3000);
                    return false;
                }
                var id = items[0][1];
                $("#Article_ID").val(id);
                $("#Article_Unit").val(items[0][3]);
                $("#BringCount").val(items[0][5]);
                $("#postid").val(items[0][6]);
                $("#clu").val(items[0][8]);
                $("#PersonName").val(items[0][11]);
                $("#HidePersonNo").val(items[0][10]);
                if (items[0][5] == "0") {
                    showLoadingMsg("您选择的物品数量为0,不能领取!", { left: 400, top: 2 }, true, 3000);
                    return false;
                }
                if ($("#PersonNo").val() == ""&&$("#NO").val()=="") {
                    showLoadingMsg("请输入您的卡号或工号", { left: 400, top: 2 }, true, 3000);
                    return false;
                }

                $.post('@Url.Action("ValidateBring")', { "postid": items[0][6], "clu": items[0][8], "personNo": items[0][10], "article_ID": id, "article_unit": items[0][3] }, function (data) {
                    if (!data) {
                        showLoadingMsg("您选择的物品已经领取过,请到规定日期再领取!", { left: 400, top: 2 }, true, 3000);
                        return false;
                    }
                    else {
                        $('#frmGroupDetail').ajaxSubmit(function (callback) {
                            if (callback) {
                                showLoadingMsg("您选择的物品领取成功", { left: 400, top: 2 }, true, 3000);
                            }
                        });

                    }
                })

            }); //end save
            $("#btnQuery").bind("click", function () {
                var no = $('#PersonNo').val() == null ? "" : $('#PersonNo').val();
                var na = $('#NO').val() == null ? "" : $('#NO').val();
                option.query = no+","+na;
                option.newp = 0;
                $('#bringList').flexOptions(option).flexReload();
            }); //end query



            //关闭
            $("#btnCancel").click(function (e) {

                $(":input").each(function () {
                    if ($(this).attr("type") == "text" || $(this).attr("type") == "textarea") {
                        $(this).val("");
                    }
                });
                $("#PersonNo").focus();
                CloseModelWindow(null, true);
            });




        }); 
       
    </script>
}
<div style="padding: 5px;">
    @using (Html.BeginForm("SaveBring", "BringArticle", FormMethod.Post, new { id = "frmGroupDetail" }))
    {
        @Html.ValidationSummary(true)
        @Html.HiddenFor(model => model.ID)
        @Html.HiddenFor(model => model.BringTime)
        @Html.HiddenFor(model => model.BringCount)
        @Html.HiddenFor(model => model.Article_ID)
        @Html.HiddenFor(model => model.Article_Unit)
        @Html.HiddenFor(model => model.clu)
        @Html.HiddenFor(model => model.postid)
        @Html.HiddenFor(model => model.PersonName)
        @Html.LabelFor(model => model.PersonNo) @Html.TextBoxFor(model => model.PersonNo)
        @Html.HiddenFor(model => model.HidePersonNo)
       <font> 工号 </font>
        @Html.TextBox("NO")
            
        <input type="button" value="查询" id="btnQuery" style="width: 62px; height: 23px;" />
        <table id="bringList" style="display: none;">
        </table>
        <br />
         
     
        <div class="buttonpanel">
            <div style="float: right; margin-right: 10px;">
                <a id="btnSave" href="javascript:void(0);" class="button"><span>保存</span></a> <a
                    id="btnCancel" href="javascript:void(0);" class="button"><span>关闭</span></a>
            </div>
        </div>
    }</div>
